package com.alageek.study;

import com.alageek.study.api.Iterator;
import com.alageek.study.entity.Book;
import com.alageek.study.entity.BookShelf;

/**
 * 迭代器模式
 */
public class Main {
    public static void main(String[] args) {
        BookShelf bookShelf = new BookShelf(4);
        bookShelf.getBooks().add(new Book("a"));
        bookShelf.getBooks().add(new Book("b"));
        bookShelf.getBooks().add(new Book("c"));
        bookShelf.getBooks().add(new Book("d"));
        bookShelf.getBooks().add(new Book("e"));
        Iterator iterator = bookShelf.iterator();
        while(iterator.hasNext()){
            System.out.println(((Book)iterator.next()).getName());
        }
    }
}
